package com.mycom.controller;

import com.mycom.controller.constant.Code;
import com.mycom.controller.entity.Result;
import com.mycom.pojo.TeamSaveItem2;
import com.mycom.service.TeamSaveItem2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teamSaveItems2")
public class TeamSaveItem2Controller {
    @Autowired
    private TeamSaveItem2Service teamSaveItem2Service;

    @PutMapping
    public Result update(@RequestBody List<TeamSaveItem2> teamSaveItem2s){
        boolean flag = true;
        for (TeamSaveItem2 teamSaveItem2 : teamSaveItem2s) {
            flag = flag & teamSaveItem2Service.update(teamSaveItem2);
        }
        Integer code = flag ? Code.UPDATE_SUCCESS : Code.UPDATE_ERR;
        String msg = flag ? "修改团队报表工作项成功！" : "修改团队报表工作项失败！";
        return new Result(code,flag,msg);
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        boolean flag = teamSaveItem2Service.deleteById(id);
        Integer code = flag ? Code.DELETE_SUCCESS : Code.DELETE_ERR;
        String msg = flag ? "删除团队报表工作项成功！" : "删除团队报表工作项失败！";
        return new Result(code,flag,msg);
    }
}
